package com.xiaojiehzu.jex.client.config;

import com.xiaojiehzu.jex.client.exception.NotFoundJexConfigException;

/**
 * @author 朱小杰
 * 时间 2017-11-05 .13:25
 * 说明 ...
 */
public class JexConfigLoaderFactory {


    /**
     * 获取配置加载器， 注解 > property > env
     * @return
     */
    public static ConfigLoader getConfigLoader(){
        ConfigLoader annotationConfigLoader = AnnotationConfigLoader.getInstance();
        if(annotationConfigLoader.isSupport()){
            return annotationConfigLoader;
        }else{
            ConfigLoader systemPropertyConfigLoader = new SystemPropertyConfigLoader();
            if(systemPropertyConfigLoader.isSupport()){
                return systemPropertyConfigLoader;
            }else{
                ConfigLoader envConfigLoader = new EnvConfigLoader();
                if(envConfigLoader.isSupport()){
                    return envConfigLoader;
                }else{
                    throw new NotFoundJexConfigException("找不到jex的配置属性");
                }
            }
        }
    }
}
